<html><head><title>test/slippy/basic_25_sorted_arrays.slippy</title></head><body>
<pre style="color: #000">

<span style="color: #390">myList</span> <span style="color: #060">=</span> <span style="color: #300">[</span><span style="color: #300">]</span>

<span style="color: #390">mySorter</span> <span style="color: #060">=</span> <span style="color: #20f">lambda</span><span style="color: #300">(</span><span style="color: #60c; font-style: italic">a</span><span style="color: #300">,</span> <span style="color: #60c; font-style: italic">b</span><span style="color: #300">)</span>
  <span style="color: #20f">if</span> <span style="color: #300">(</span><span style="color: #000; font-style: italic">a</span> <span style="color: #060">></span> <span style="color: #000; font-style: italic">b</span><span style="color: #300">)</span>
    <span style="color: #000">1</span>
  <span style="color: #20f">else</span> <span style="color: #20f">if</span> <span style="color: #300">(</span><span style="color: #000; font-style: italic">a</span> <span style="color: #060"><</span> <span style="color: #000; font-style: italic">b</span><span style="color: #300">)</span>
    <span style="color: #060">-</span><span style="color: #000">1</span>
  <span style="color: #20f">else</span>
    <span style="color: #000">0</span>
  <span style="color: #000">done</span> 
<span style="color: #000">done</span>

<span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #c60; font-style: italic">"lambda(1, 2) should be negative: "</span> <span style="color: #060">+</span> <span style="color: #600">mySorter</span><span style="color: #300">(</span><span style="color: #000">1</span><span style="color: #300">,</span> <span style="color: #000">2</span><span style="color: #300">)</span><span style="color: #300">)</span>
<span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #c60; font-style: italic">"lambda(3, 2) should be positive: "</span> <span style="color: #060">+</span> <span style="color: #600">mySorter</span><span style="color: #300">(</span><span style="color: #000">3</span><span style="color: #300">,</span> <span style="color: #000">2</span><span style="color: #300">)</span><span style="color: #300">)</span>
<span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #c60; font-style: italic">"lambda(2, 2) should be zero: "</span> <span style="color: #060">+</span> <span style="color: #600">mySorter</span><span style="color: #300">(</span><span style="color: #000">2</span><span style="color: #300">,</span> <span style="color: #000">2</span><span style="color: #300">)</span><span style="color: #300">)</span>

<span style="color: #003">myList</span><span style="color: #390">.</span><span style="color: #390">sort</span> <span style="color: #060">=</span> <span style="color: #000; font-style: italic">mySorter</span>
<span style="color: #003">myList</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">3</span><span style="color: #300">)</span>
<span style="color: #003">myList</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">4</span><span style="color: #300">)</span>
<span style="color: #003">myList</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">1</span><span style="color: #300">)</span>
<span style="color: #003">myList</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">4</span><span style="color: #300">)</span>
<span style="color: #003">myList</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">5</span><span style="color: #300">)</span>
<span style="color: #003">myList</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">2</span><span style="color: #300">)</span>
<span style="color: #003">myList</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">0.5</span><span style="color: #300">)</span>
<span style="color: #003">myList</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">6.5</span><span style="color: #300">)</span>
<span style="color: #003">myList</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">0.5</span><span style="color: #300">)</span>

<span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #c60; font-style: italic">"The following should be in nondecreasing order:"</span><span style="color: #300">)</span>
<span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #c60; font-style: italic">"myList is: "</span> <span style="color: #060">+</span> <span style="color: #000; font-style: italic">myList</span><span style="color: #300">)</span>

<span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #c60; font-style: italic">"Popping last element."</span><span style="color: #300">)</span>
<span style="color: #003">myList</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">removeAtIndex</span><span style="color: #300">(</span><span style="color: #003">myList</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">n</span><span style="color: #300">(</span><span style="color: #300">)</span> <span style="color: #060">-</span> <span style="color: #000">1</span><span style="color: #300">)</span>
<span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #c60; font-style: italic">"myList is: "</span> <span style="color: #060">+</span> <span style="color: #000; font-style: italic">myList</span><span style="color: #300">)</span>

<span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #c60; font-style: italic">"Adding PI."</span><span style="color: #300">)</span>
<span style="color: #003">myList</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000; font-style: italic">PI</span><span style="color: #300">)</span>
<span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #c60; font-style: italic">"myList is: "</span> <span style="color: #060">+</span> <span style="color: #000; font-style: italic">myList</span><span style="color: #300">)</span>

<span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #c60; font-style: italic">"Now I am going to start with a jumbled list and ask it to resort."</span><span style="color: #300">)</span>

<span style="color: #093; font-style: italic">; jumble = [ 3, 1, 6, 6, 8, 5, 2, 6, 4 ]
</span>
<span style="color: #390">s</span> <span style="color: #060">=</span> <span style="color: #20f">lambda</span><span style="color: #300">(</span><span style="color: #60c; font-style: italic">a</span><span style="color: #300">,</span> <span style="color: #60c; font-style: italic">b</span><span style="color: #300">)</span>
  <span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #c60; font-style: italic">"comparing '"</span> <span style="color: #060">+</span> <span style="color: #000; font-style: italic">a</span> <span style="color: #060">+</span> <span style="color: #c60; font-style: italic">"' and '"</span> <span style="color: #060">+</span> <span style="color: #000; font-style: italic">b</span> <span style="color: #060">+</span> <span style="color: #c60; font-style: italic">"'"</span><span style="color: #300">)</span>
  <span style="color: #20f">if</span> <span style="color: #300">(</span><span style="color: #000; font-style: italic">a</span> <span style="color: #060"><</span> <span style="color: #000; font-style: italic">b</span><span style="color: #300">)</span>
     <span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #000; font-style: italic">a</span><span style="color: #300">,</span> <span style="color: #c60; font-style: italic">"is less than"</span><span style="color: #300">,</span> <span style="color: #000; font-style: italic">b</span><span style="color: #300">)</span>
    <span style="color: #060">-</span><span style="color: #000">1</span>
  <span style="color: #20f">else</span> <span style="color: #20f">if</span> <span style="color: #300">(</span><span style="color: #000; font-style: italic">a</span> <span style="color: #060">></span> <span style="color: #000; font-style: italic">b</span><span style="color: #300">)</span>
    <span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #000; font-style: italic">a</span><span style="color: #300">,</span> <span style="color: #c60; font-style: italic">"is greater than"</span><span style="color: #300">,</span> <span style="color: #000; font-style: italic">b</span><span style="color: #300">)</span>
    <span style="color: #000">1</span>
  <span style="color: #20f">else</span>
    <span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #000; font-style: italic">a</span><span style="color: #300">,</span><span style="color: #c60; font-style: italic">"=="</span><span style="color: #300">,</span> <span style="color: #000; font-style: italic">b</span><span style="color: #300">)</span>
    <span style="color: #000">0</span>
  <span style="color: #000">done</span>
<span style="color: #000">done</span>

<span style="color: #390">jumble</span> <span style="color: #060">=</span> <span style="color: #300">[</span><span style="color: #300">]</span>
<span style="color: #390">jumble</span><span style="color: #390">.</span><span style="color: #390">sort</span> <span style="color: #060">=</span> <span style="color: #000; font-style: italic">s</span>
<span style="color: #003">jumble</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">3</span><span style="color: #300">)</span>
<span style="color: #003">jumble</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">1</span><span style="color: #300">)</span>
<span style="color: #003">jumble</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">6</span><span style="color: #300">)</span>
<span style="color: #003">jumble</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">6</span><span style="color: #300">)</span>
<span style="color: #003">jumble</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">8</span><span style="color: #300">)</span>
<span style="color: #003">jumble</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">5</span><span style="color: #300">)</span>
<span style="color: #003">jumble</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">2</span><span style="color: #300">)</span>
<span style="color: #003">jumble</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">6</span><span style="color: #300">)</span>
<span style="color: #003">jumble</span><span style="color: #000; font-weight: bold">.</span><span style="color: #600">add</span><span style="color: #300">(</span><span style="color: #000">4</span><span style="color: #300">)</span>
<span style="color: #093; font-style: italic">;ordered = jumble.resort(s)
</span>
<span style="color: #600">print</span><span style="color: #300">(</span><span style="color: #c60; font-style: italic">"jumble   : "</span> <span style="color: #060">+</span> <span style="color: #000; font-style: italic">jumble</span><span style="color: #300">)</span>
<span style="color: #093; font-style: italic">;print("ordered  : " + ordered)
</span>
</pre>
</body></html>
